package com.jugheadzhou.streamproducer.service;

import com.jugheadzhou.core.message.CustomSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

/**
 * 使用自定义输出管道发送消息
 *
 * @author jugheadzhou
 * @date 2021-09-28
 */
@Slf4j
@EnableBinding(CustomSource.class)
public class CustomService {

    @Resource
    private CustomSource customSource;

    /**
     * 通过自定义消息通道发送消息
     *
     * @param msg
     */
    public void sendMsg(String msg){
        log.info("通过自定义消息通道[{}]发送消息: {}", CustomSource.OUTPUT, msg);
        customSource.output().send(MessageBuilder.withPayload(msg).build());
    }
}
